package com.choosefine.it.common.conf;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;

@Configuration
	public class CorsConfig {
	    private CorsConfiguration buildConfig() {
	        CorsConfiguration corsConfiguration = new CorsConfiguration();
	        corsConfiguration.addAllowedOrigin("*"); // 1
	        corsConfiguration.addAllowedHeader("*"); // 2
	        corsConfiguration.addAllowedMethod("*"); // 3
	        return corsConfiguration;
	    }

	    @Bean
	    public org.springframework.web.filter.CorsFilter corsFilter() {
	        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
	        source.registerCorsConfiguration("/**", buildConfig()); // 4
	        return new org.springframework.web.filter.CorsFilter(source);
	    }
	}
